<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo Yii::$app->name;?> 后台管理</title>
<?php $this->HeaderView();?>
<script>
var form_validator;
function addrules(obj, rules){
	//alert(obj)
	$(obj).rules("add", rules);
	
}
</script>
</head>
<body class="view_form" id="view_form_Model">
<?php
use \backend\modules\mobo\models\Models;
?>
<div class="view-index-nav">
        <h3><?php echo $model->fieldid ? '编辑' : '' ?>自定义字段</h3>
  <p class="tips">
        <strong style="color:#F00">屏蔽</strong>的帖子在前台只有版主可见。
        </p>
</div>
        <form class="view-form-form" style="padding:0px 20px 20px 20px" method="post" action="<?php echo $this->createUrl([($model->fieldid ? 'mobo/models/update-field' : 'mobo/models/create-field'), 'modelid'=>$modelid ,'fieldid'=>$model->fieldid]);?>" enctype="multipart/form-data">
        <input type="hidden" name="Field[modelid]" id="modelid" value="<?php echo $modelid;?>"  />
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="40%" style="border-right: 2px solid #ddd; padding-top:20px;">

            <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <thead>

                                        <tr>
                        <th valign="top" class="td-title"><label for="catid"><font class="required">*</font>控件类型：</label></th>
                        <td class="td-input ch-select" z-index="199">
                        <select style="visibility:hidden; width:0px; height:0px" data-value="<?php echo $model->formtype?>" name="Field[formtype]" id="formtype"<?php if ($model->formtype) echo ' disabledd="disabled"';?>>
                        <option value="">控件类型</option>
                        <?php
						foreach(Models::formtype() as $k=>$v){
						echo '<option value="'.$k.'">'.$v.'</option>';
						}
						?>
                        </select>
                        </td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid"><font class="required">*</font>字段类型：</label></th>
                        <td class="td-input ch-select" z-index="98">
                        <select style="visibility:hidden; width:0px; height:0px" data-value="<?php echo $model->fieldtype?>" name="Field[fieldtype]" id="fieldtype"<?php if ($model->fieldtype) echo ' disabled="disabled"';?>>
                        <option value="">字段类型</option>
                        <option value="int">int</option>
                        <option value="tinyint">tinyint</option>
                        <option value="varchar">varchar</option>
                        <option value="text">text</option>
                        </select>&nbsp;&nbsp;
                        (<input style="width:30px" type="text" class="input-text" id="fieldlength" name="Field[fieldlength]" value="<?php echo $model->fieldlength;?>" <?php if ($model->fieldtype) echo ' readonly="readonly"';?>>)
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid"><font class="required">*</font>主表字段：</label></th>
                        <td class="td-input">
                        <p class="field btn-select" id="change-primarytable">
                            <select name="Field[primarytable]" id="primarytable" class="hidden" <?php if ($model->fieldid) echo ' disabled="disabled"';?>>
                                <option value="1" <?php if ((intval($model->primarytable)==1)) echo ' selected';?>>是</option>
                                <option value="0" <?php if (intval($model->primarytable)==0) echo ' selected';?>>否</option>
                            </select>
                        </p>
                        </td>
                    </tr>
                    

                                        <tr>
                        <th valign="top" class="td-title"><label for="catid"><font class="required">*</font>字段名：</label></th>
                        <td class="td-input"><input style="width:80px" type="text" class="input-text" id="field" name="Field[field]" value="<?php echo $model->field;?>"<?php if ($model->fieldtype) echo ' readonly="readonly"';?>></td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid"><font class="required">*</font>字段标题：</label></th>
                        <td class="td-input"><input style="width:80px" type="text" class="input-text" id="name" name="Field[name]" value="<?php echo $model->name;?>"></td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">是否必填：</label></th>
                        <td class="td-input">
                        <p class="field btn-select" id="change-required">
                            <select name="Field[required]" id="required" class="hidden">
                                <option value="1" <?php if ((intval($model->required)==1)) echo ' selected';?>>是</option>
                                <option value="0" <?php if (intval($model->required)==0) echo ' selected';?>>否</option>
                            </select>
                        </p>
                        </td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">默认值：</label></th>
                        <td class="td-input"><input style="width:80px" type="text" class="input-text" id="defaultvalue" name="Field[setting][defaultvalue]" value="<?php echo isset($model->setting['defaultvalue']) ? $model->setting['defaultvalue'] : '';?>"></td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">输入提示：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="inputtip" name="Field[setting][inputtip]" value="<?php echo isset($model->setting['inputtip']) ? $model->setting['inputtip'] : '';?>"></td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">字段长度限制：</label></th>
                        <td class="td-input"><input style="width:30px" type="text" class="input-text" id="minlength" name="Field[setting][minlength]" value="<?php echo isset($model->setting['minlength']) ? $model->setting['minlength'] : '';?>"> - <input style="width:30px" type="text" class="input-text" id="maxlength" name="Field[setting][maxlength]" value="<?php echo isset($model->setting['maxlength']) ? $model->setting['maxlength'] : '';?>"></td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">数据校验正则：</label></th>
                        <td class="td-input"><input style="width:80px" type="text" class="input-text ftl" id="pattern" name="Field[setting][pattern]" value="<?php echo isset($model->setting['pattern']) ? $model->setting['pattern'] : '';?>">
                        <label class="ch-select">
                        <select style="visibility:hidden; width:0" name="pattern_select" onchange="javascript:$('#pattern').val(this.value)">
<option value="">常用正则</option>
<option value="/^[0-9.-]+$/">数字</option>
<option value="/^[0-9-]+$/">整数</option>
<option value="/^\+?[1-9][0-9]*$/">正整数</option>
<option value="/^[a-z]+$/i">字母</option>
<option value="/^[0-9a-z]+$/i">数字+字母</option>
<option value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
<option value="/^[0-9]{5,20}$/">QQ</option>
<option value="/^http:\/\//">超级链接</option>
<option value="/^(1)[0-9]{10}$/">手机号码</option>
<option value="/^[0-9-]{6,13}$/">电话号码</option>
<option value="/^[0-9]{6}$/">邮政编码</option>
</select>
</label>
                        </td>
                    </tr>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">数据校验未通过提示：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="errortip" name="Field[setting][errortip]" value="<?php echo isset($model->setting['errortip']) ? $model->setting['errortip'] : '';?>"></td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">搜索字段：</label></th>
                        <td class="td-input">
                        <p class="field btn-select" id="change-required">
                            <select name="Field[setting][search]" id="search" class="hidden">
                                <option value="1" <?php if (@intval($model->setting['search'])==1) echo ' selected';?>>是</option>
                                <option value="0" <?php if (@intval($model->setting['search'])==0) echo ' selected';?>>否</option>
                            </select>
                        </p>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">允许后台填写：</label></th>
                        <td class="td-input">
                        <p class="field btn-select" id="change-allowinput">
                            <select name="Field[allowinput]" id="allowinput" class="hidden">
                                <option value="1" <?php if ($model->allowinput=='' || intval($model->allowinput)==1) echo ' selected';?>>是</option>
                                <option value="0" <?php if ((string)$model->allowinput=='0') echo ' selected';?>>否</option>
                            </select>
                        </p>
                        </td>
                    </tr>
                    
                        </tbody>
            </table>
        
        </td>
        <td valign="top" style="padding-top:20px;">
            <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                    <tr>
                    <td class="td-input" id="setting" style="border:none; padding:0"></td>
                    </tr>
            </table>
        </td>
    </tr>
                        <tr>
                        <th><input type="submit" value="提交" name="sbmt" class="btn-submit mt-10"></th>
                        <td>
                            </td>
                    </tr>
</table>
<?=$this->csrfToken()?>

    </form>

<?php $this->FooterView();?>
<script type="text/javascript">
function setting(){
	var val = $('#formtype').val();
	var url = '<?php echo $this->createUrl('mobo/models/formfield');?>';
	var data = {formtype : val};
	if (val){
		$.getJSON(url, data, function(data){
			$('#setting').html(data.form);
		});
	}

}
$(function(){
	//需要表单验证的请在这里配置，文档
	$.validator.addMethod("ckfield", function(value, element) {
	    var chrnum = /^([a-zA-Z0-9_]+)$/;
	    return this.optional(element) || (chrnum.test(value));
	}, "只能输入数字和字母和下划线");
	form_validator = $(".view-form-form").validate({
		//debug:true, //如果只调试验证不提交数据，可开启这里
		rules: {
			'Field[fieldtype]':{
				required:true,
			},
			'Field[formtype]':{
				required:true,
			},
			'Field[field]':{
				required:true,
				maxlength: 30,
				ckfield:'',
				
			},
			'Field[name]':{
				required:true,
				maxlength: 30
			}
		},
		messages: {
			'Field[fieldtype]':{
				required:'请选择字段类型',
			},
			'Field[formtype]':{
				required:'请选择控件类型',
			},
			'Field[field]':{
				required:'请输入字段名',
				maxlength:'入字段名长度少于30个字符'
			},
			'Field[name]':{
				required:'请输入字段标题',
				maxlength:'标题长度少于30个字符'
			}
                    
		}
	});
	setting();
	$('#formtype').on('change', function(){
		setting();
	}).val('<?php echo $model->formtype;?>');
	
	
	
	
});
</script>
</body>
</html>
